package com.aispeech.imgany;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

import com.aispeech.AISpeech;
import com.aispeech.imgany.engineSdk.SampleConstants;


/**
 * @author rain  02.28 2018
 */

public class MyApplication extends Application {

    private static String TAG = "SpeechApplication";
    private static Context mContext;
    public static int width;
    public static int height;
    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
//        AISpeech.openLog();
        int result = AISpeech.init(mContext, SampleConstants.APPKEY, SampleConstants.SECRETKEY);//这里的context一定要传Application的context，它的生命周期会贯穿整个应用的生命周期
        if (result == 0) {
            Log.d(TAG, "AISpeech sdk init ok");

            Log.d(TAG, "onCreate: start ai engine service !");
            startService(new Intent(this, ControlService.class));
        } else {
            Log.d(TAG, "AISpeech sdk init error : " + AISpeech.getErrorText(result));
        }
        //		AISpeech.setEchoEnable(true);// 打开AEC
        //		AISpeech.setEchoCfgFile("MIC2_2_MIC1_AEC_1ref_mute0_512.bin");// 设置AEC的配置文件
        //		AISpeech.setAecSavedPath("/sdcard/aispeech/aecPcmFile/");//设置aec保存的音频文件路径
        //		AISpeech.setRecChannel(2);// 默认为1,即左通道为rec录音音频,右通道为play参考音频（播放音频）若设置为2,
        // 通道会互换，即左通道为play参考音频（播放音频）,右通道为rec录音音频

        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        width = dm.widthPixels;         // 屏幕宽度（像素）
        height = dm.heightPixels;       // 屏幕高度（像素）
    }

    public static Context getContext() {
        return mContext;
    }
}
